﻿using System;



namespace CylinderApplication

{

    // (1) 定义接口A

    interface A

    {

        double Area();

    }



    // (2) 定义接口B

    interface B

    {

        void SetColor(string c);

    }



    // (3) 定义接口C，继承接口A和B

    interface C : A, B

    {

        void Volume();

    }



    // (4) 定义圆柱体类Cylinder实现接口C

    class Cylinder : C

    {

        // 成员变量

        private double radius;

        private double height;

        private string color;



        // 构造方法

        public Cylinder(double radius, double height, string color)

        {

            this.radius = radius;

            this.height = height;

            this.color = color;

        }



        // 实现接口A的方法

        public double Area()

        {

            return Math.PI * radius * radius;

        }



        // 实现接口B的方法

        public void SetColor(string c)

        {

            color = c;

        }



        // 实现接口C的方法

        public void Volume()

        {

            double volume = Area() * height;

            Console.WriteLine($"圆柱体体积: {volume:F2}");

        }



        // 显示圆柱体信息的方法

        public void DisplayInfo()

        {

            Console.WriteLine($"圆柱体信息: 半径={radius}, 高={height}, 颜色={color}");

            Console.WriteLine($"底面积: {Area():F2}");

            Volume();

            Console.WriteLine();

        }

    }



    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("圆柱体计算程序");

            Console.WriteLine("==============");

            Console.WriteLine();



            // (5) 测试类Cylinder

            // 创建圆柱体对象

            Cylinder cylinder1 = new Cylinder(3.0, 5.0, "红色");

            Console.WriteLine("圆柱体1:");

            cylinder1.DisplayInfo();



            // 使用接口A引用

            A a = cylinder1;

            Console.WriteLine($"通过接口A调用Area(): {a.Area():F2}");

            Console.WriteLine();



            // 使用接口B引用

            B b = cylinder1;

            Console.WriteLine("通过接口B调用SetColor():");

            b.SetColor("蓝色");

            cylinder1.DisplayInfo();



            // 使用接口C引用

            C c = cylinder1;

            Console.WriteLine("通过接口C调用Volume():");

            c.Volume();

            Console.WriteLine();



            // 创建更多圆柱体进行测试

            Cylinder cylinder2 = new Cylinder(2.5, 4.0, "绿色");

            Console.WriteLine("圆柱体2:");

            cylinder2.DisplayInfo();



            Cylinder cylinder3 = new Cylinder(1.0, 10.0, "黄色");

            Console.WriteLine("圆柱体3:");

            cylinder3.DisplayInfo();



            // 测试接口的多态性

            Console.WriteLine("接口多态性测试:");

            A[] shapes = new A[3];

            shapes[0] = new Cylinder(2.0, 3.0, "紫色");

            shapes[1] = new Cylinder(4.0, 2.0, "橙色");

            shapes[2] = new Cylinder(1.5, 5.0, "粉色");



            foreach (A shape in shapes)

            {

                Console.WriteLine($"面积: {shape.Area():F2}");

            }



            Console.ReadLine();

        }

    }

}